package math;

import java.io.FileNotFoundException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class RWFile {
    //exemple : //home/me/Documents/ToWindows/matrix1.txt

    public static void writeTextToFile(String texttowrite, String fileaddr) {
        try {
            FileWriter fw = new FileWriter(fileaddr, false);
            BufferedWriter output = new BufferedWriter(fw);
            output.write(texttowrite);
            output.flush();
            output.close();
        } catch (IOException ioe) {
            System.out.println("error " + ioe);
        }
    }

    public static String readFromFile(String fileaddr) throws FileNotFoundException {
        String ret = "";
        Scanner scanner = new Scanner(new File(fileaddr));
        while (scanner.hasNextLine()) {
            ret += scanner.nextLine() + "\n";
        }
        scanner.close();
        return ret;
    }
}
